const department1 = ['全市', '茂南', '电白', '高州', '化州', '信宜'],
  department2 = [
    [],
    ['开发区', '茂北', '西城', '油城北', '油城东', '油城南东', '油城南西'],
    ['滨海', '林头', '麻岗', '南海', '沙琅', '水东'],
    ['大井', '高城北', '高城南', '根子', '石鼓', '长坡'],
    ['合江', '河东', '化北', '化河西', '同庆', '杨梅'],
    ['北界', '城北', '城南', '合水', '钱排', '朱砂']
  ];

const departOrder = department1
  .reduce((p, d1, i) => {
    return p.concat(d1, department2[i])
  }, [])
  .reduce((p, c, i) => { p[c] = i; return p }, {})

export default {
  departOrder,
  department1,
  department2,
  allDepartment: department1.reduce((all, d1, index) => {
    all = all.concat(d1, department2[index])
    return all;
  }, []),
  mergeSelection: (selectedDepartment) => {
    let mergeDepartment;
    if (selectedDepartment[0].includes('全市') || selectedDepartment[1].length === 0) {
      mergeDepartment = ['全市']
    } else if (selectedDepartment[0].length === 1 && selectedDepartment[1].every(v => department2[department1.indexOf(selectedDepartment[0][0])].includes(v))) {
      mergeDepartment = selectedDepartment[0]
    } else {
      mergeDepartment = selectedDepartment.flat();
    }
    console.log('mergeDepartment', mergeDepartment);
    return mergeDepartment;
  }
}

